package com.chtw.oasystem.config;

import com.chtw.oasystem.interceptor.LoginInterceptor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class LoginInterceptorConfig implements WebMvcConfigurer {
    @Bean
    public WebMvcConfigurer webMvcConfigurerAdapter() {
        return new WebMvcConfigurer() {
            @Value("${lcbs.filepath}")
            private String filePath; //配置文件配置的物理保存地址
            @Value("${lcbs.fileroot}")
            private String fileroot;
            //注册拦截器
            @Override
            public void addInterceptors(InterceptorRegistry registry) {
                registry.addInterceptor(new LoginInterceptor()).addPathPatterns("/**")
                        .excludePathPatterns("/user/login")
                        .excludePathPatterns("/state/*")
                        .excludePathPatterns("/train/*")
                        .excludePathPatterns("/file/*")
                        .excludePathPatterns("/"+fileroot+"/*");
            }

            @Override
            public void addResourceHandlers(ResourceHandlerRegistry registry) {
                registry.addResourceHandler("/"+fileroot+"/**").addResourceLocations("file:"+filePath +"/");
            }

        };
    }

}
